package com.yueka.controller;

import com.yueka.pojo.R;
import com.yueka.pojo.entity.teacher.Teacher;
import com.yueka.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/teacher")
@RestController
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @PostMapping("/insert")
    public R insertTeacher(@RequestBody Teacher teacher) {
        try {
            teacherService.insertTeacher(teacher);
            return R.success();
        } catch (Exception e) {
            return R.error("新增失败");
        }
    }

    @GetMapping("/list")
    public R listTeachers(String keyword, String status, Integer page, Integer pageSize) {
        try {
            return R.success(teacherService.listTeachers(keyword, status, page, pageSize));
        } catch (Exception e) {
            return R.error("查询失败");
        }
    }

    @PostMapping("/update")
    public R updateTeacher(@RequestBody Teacher teacher) {
        try {
            teacherService.updateTeacher(teacher);
            return R.success();
        } catch (Exception e) {
            return R.error("更新失败");
        }
    }

    @GetMapping("/delete")
    public R deleteTeacher(Integer[] ids) {
        try {
            teacherService.deleteTeacher(ids);
            return R.success();
        } catch (Exception e) {
            return R.error("删除失败");
        }
    }
}
